package com.dongdongshop.service;

import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class BrandServiceImpl implements BrandService {
    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Override
    public List<TbBrand> brandList() {
        List<TbBrand> tbBrands = tbBrandMapper.selectByExample(null);
        return tbBrands;
    }

    @Override
    public TbBrand selectById(Long id) {
        TbBrand tbBrand = tbBrandMapper.selectByPrimaryKey(id);
        return tbBrand;
    }

    @Override
    public Page<TbBrand> brandPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> tbBrands = tbBrandMapper.selectByExample(null);
        PageInfo info = new PageInfo(tbBrands);
        return new Page(info.getPageNum(),info.getPageSize(),info.getPages(),info.getTotal(),info.getList());
    }

    @Override
    public int deleteByIds(Integer[] ids) {
        int i = tbBrandMapper.deleteByids(ids);
        return i;
    }

    @Override
    public int updatebyid(TbBrand tbBrand) {
        int i = tbBrandMapper.updateByPrimaryKey(tbBrand);
        return i;
    }

    @Override
    public int insertAll(TbBrand tbBrand) {
        int i = tbBrandMapper.insert(tbBrand);
        return i;
    }

}
